<form id="pagerForm" method="post" action="<?php echo SITE_URL . 'index.php?c=role&a=ajaxLookUp';?>">
    <input type="hidden" name="pageNum" value="1" />
    <input type="hidden" name="numPerPage" value="<?php echo $list['pager']->per_page;?>" />
    <input type="hidden" name="role_name" value="<?php echo $_input->post('role_name');?>" />
</form>

<div class="pageHeader">
	<form rel="pagerForm" method="post" action="<?php echo SITE_URL . 'index.php?c=role&a=ajaxLookUp';?>" onsubmit="return dwzSearch(this, 'dialog');">
	<div class="searchBar">
		<table class="searchContent">
			<tr>
				<td>
					角色名：<input type="text" name="role_name" />
				</td>
                <td><div class="button"><div class="buttonContent"><button type="submit">搜索</button></div></div></td>
			</tr>
		</table>
	</div>
	</form>
</div>
<div class="pageContent">
	<table class="table" width="100%" targettype="dialog" layoutH="97">
		<thead>
			<tr>
                <th width="22" align="center"><input type="checkbox" group="ids" class="checkboxCtrl"></th>
                <th width="30" align="center">ID</th>
				<th width="50" align="center">角色名称</th>
			</tr>
		</thead>
		<tbody>
            <?php foreach($list['rs'] as $v){?>
            <tr target="sid" rel="<?php echo $v['role_id'];?>">
                <td><input name="ids" value="<?php echo $v['role_id'].'_'.$v['role_name'];?>" type="checkbox"></td>
                <td><?php echo $v['role_id'];?></td>
                <td><?php echo $v['role_name'];?></td>
            </tr>
            <?php }?>
		</tbody>
	</table>
	<div class="formBar">
		<ul>
			<li><a class="button"  href="javascript:void(0);" onclick="addRoleCallBack();"><span>确认</span></a></li>
			<li><div class="button"><div class="buttonContent"><button class="close" type="button">关闭</button></div></div></li>
		</ul>
	</div>
</div>
<script type="text/javascript">
function addRoleCallBack(){
    var pdialog = $("body").data('<?php echo $parent_rel;?>');
    var dialog = $("body").data('role_lookup');
    var role_ids = [],role_names = [];
    dialog.find("input:checked").filter("[name='ids']").each(function(i){
        var _r = $(this).val().split('_');
        role_ids.push(_r[0]);
        role_names.push(_r[1]);
    });
    $('input[name="role_ids"]', pdialog).val(role_ids.join(','));
    $('textarea[name="role_names"]', pdialog).val(role_names.join(','));
    $.pdialog.closeCurrent();
}

(function($){
    var pdialog = $("body").data('<?php echo $parent_rel;?>');
    var sids = $('input[name="role_ids"]', pdialog).val().split(',');
    setTimeout(function(){//这里代码有延迟事件，所以用setTimeout调整执行顺序
        var dialog = $("body").data('role_lookup');
        dialog.find("input[name='ids']").each(function(i){
            if($.inArray($(this).val().split('_')[0],sids) != -1){
                $(this).attr('checked',true);
            }
        });
    },0);
})(jQuery);
</script>